/**
 * Copyright (c) 2009-2012 XTEAM
 * All rights reserved.
 */
/**
 * File：NormalAction.java
 * History:
 *         2012-6-15: Initially created, Chrise.
 */
package com.xteam.ecsystem.action;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.xteam.ecsystem.system.ConfigManager;
import com.xteam.ecsystem.utils.FrontUtil;

/**
 * 标准请求控制层。
 * @author Chrise
 */
@Controller
public class NormalAction {
	
	@Autowired
	private ConfigManager cfgManager;
	
	/**
	 * 默认请求。
	 * @author Chrise 2012-6-19
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String def(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws IOException {
		return this.index(request, response, model);
	}
	
	/**
	 * 主页请求。
	 * @author Chrise 2012-12-19
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/index.xhtml", method = RequestMethod.GET)
	public String index(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws IOException {
		return this.common(request, response, model);
	}
	
	/**
	 * 公共请求。
	 * @author Chrise 2012-6-19
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/**/*.xhtml", method = RequestMethod.GET)
	public String common(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws IOException {
		//获取模板路径
		String template = FrontUtil.getTemplatePath(request, response, this.cfgManager);
		if (template != null) {
			//设置公共数据
			FrontUtil.setCommons(request, response, model, this.cfgManager.getSystemConfig(), this.cfgManager.getWebConfig());
		}
		
		return template;
	}
	
}
